/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GameScheduleSettingPanel.java
 *
 * Created on 2009-9-26, 9:54:44
 */
package com.res0w.SMMS.ui.admin;

import com.res0w.SMMS.admin.Schedule;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;

/**
 *
 * @author Administrator
 */
public class GameScheduleSettingPanel extends javax.swing.JPanel {

    /** Creates new form GameScheduleSettingPanel */
    public GameScheduleSettingPanel() {
        initComponents();
        scheduleRead();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        scheduleTable = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        submitBtn = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(950, 570));

        jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18));
        jLabel1.setText("赛程安排：");

        scheduleTable.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        scheduleTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object[][]{
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},
                {"", "", "", ""},},
            new String[]{
                "项目次序", "项目名称", "举行时间", "举行地点"
            }) {

                Class[] types = new Class[]{
                    java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
                };

                public Class getColumnClass(int columnIndex) {
                    return types[columnIndex];
                }
            });
            jScrollPane1.setViewportView(scheduleTable);
            scheduleTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(itemsListCombox));

            jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 18));
            jLabel2.setText("使用提示：");

            jTextArea1.setColumns(20);
            jTextArea1.setEditable(false);
            jTextArea1.setFont(new java.awt.Font("微软雅黑", 0, 13));
            jTextArea1.setRows(5);
            jTextArea1.setText("项目次序：\n项目次序输入类型只能是【数字】，按照比赛的循序进行递加\n若两个项目同时举行则项目次序一致。\n\n项目名称：\n项目从下拉菜单中选择\n\n举行时间：\n此项为项目的举行时间，输入格式为自由格式：\n如：【**年*月*日*时*日*时】\n或者【赛程第一天下午第*项】等可以表示时间次序均可\n\n举行地点：\n此项为项目的举行地点，输入格式为自由格式：\n如：【400米跑道】，【篮球场】等均可");
            jScrollPane2.setViewportView(jTextArea1);

            submitBtn.setText("提交");
            submitBtn.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    submitBtnActionPerformed(evt);
                }
            });

            jButton2.setText("全部重写");

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(51, 51, 51)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(31, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(677, Short.MAX_VALUE)
                    .addComponent(jButton2)
                    .addGap(59, 59, 59)
                    .addComponent(submitBtn)
                    .addGap(76, 76, 76))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(47, 47, 47)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane2)
                        .addComponent(jScrollPane1))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(submitBtn)
                        .addComponent(jButton2))
                    .addContainerGap(46, Short.MAX_VALUE))
            );
        }// </editor-fold>//GEN-END:initComponents

    private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitBtnActionPerformed
        // TODO add your handling code here:
        submit();
    }//GEN-LAST:event_submitBtnActionPerformed

//Create By Author:
    private void submit() {

        Schedule data = new Schedule();
        int i = 0;
        while (scheduleTable.getValueAt(i, 0).toString() != "") {
           //项目次序
            data.ItemsPriority=Integer.parseInt
                    (scheduleTable.getValueAt(i, 0).toString());
            //项目名称
            data.itemsName=scheduleTable.getValueAt(i, 1).toString();
            //举行时间
            data.itemsDate=scheduleTable.getValueAt(i, 2).toString();
            //举行地点
            data.itemsLocation=scheduleTable.getValueAt(i, 3).toString();
            data.scheduleUpdate(false);
            i++;
        }
        data.onlyExe4Schedule();
    }
    private void scheduleRead(){
        Schedule data = new Schedule();
        data.scheduleRead();
        for(int i=0;i<data.scheduleList.size();i=i+5){
             int editRow = i / 5;
            scheduleTable.setValueAt(data.scheduleList.get(i), editRow, 0);
            scheduleTable.setValueAt(data.scheduleList.get(i+1), editRow, 1);
            scheduleTable.setValueAt(data.scheduleList.get(i+2), editRow, 2);
            scheduleTable.setValueAt(data.scheduleList.get(i+3), editRow, 3);
        }
    }
    private Schedule sc = new Schedule();
    private JComboBox itemsListCombox = new JComboBox(sc.readFullItems());
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTable scheduleTable;
    private javax.swing.JButton submitBtn;
    // End of variables declaration//GEN-END:variables
}
